import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';

// import { useI18n } from '/@/hooks/web/useI18n';
import { useMessage } from '/@/hooks/web/useMessage';
import { defHttp } from '/@/utils/http/axios';

// 请求连接路径
enum Api {
  PageList = '/gen/data/listByPage',
  Add = '/gen/data/add',
  Edit = 'gen/data/edit',
  Delete = 'gen/data/delete?id=',
  TestGenDb = 'gen/data/test',
}
// const { t } = useI18n();
const { createMessage } = useMessage();
const { success } = createMessage;
// 获取分页信息
export const getListByPage = (params?: any) => defHttp.get<any>({ url: Api.PageList, params });
// 添加
export const addSpaUser = (params?: any) => {
  return defHttp.post<any>({ url: Api.Add, params }).then(() => {
    success('Success message');
  });
};
// 修改
export const editSpaUser = (params?: any) => {
  return defHttp.put<any>({ url: Api.Edit, params }).then(() => {
    success('Success message');
  });
};

// 删除字典
export const deleteSpaUser = (id, handleSuccess) => {
  return defHttp.delete({ url: Api.Delete + id }).then(() => {
    success('Success message');
    handleSuccess();
  });
};

// 测试数据源
export const testGenDb = (params?: any) => {
  defHttp.post<any>({ url: Api.TestGenDb, params }).then((r) => {
    console.log(r);
    success('连接成功！');
  });
};

// 列表
export const columns: BasicColumn[] = [
  {
    title: '数据源名称',
    dataIndex: 'dbName',
    width: 200,
  },
  {
    title: '目录',
    dataIndex: 'catalog',
    width: 200,
  },
  {
    title: '驱动类',
    dataIndex: 'drive',
    width: 200,
  },
  {
    title: '数据源URL',
    dataIndex: 'dbUrl',
    width: 200,
  },
  {
    title: '账号',
    dataIndex: 'dbUsername',
    width: 200,
  },
];

// 查询条件
export const searchFormSchema: FormSchema[] = [
  {
    field: 'dbName',
    label: '数据源名称',
    component: 'Input',
    colProps: { span: 8 },
  },
];

// 编辑
export const formSchema: FormSchema[] = [
  {
    field: 'id',
    label: '唯一标识',
    required: false,
    component: 'Input',
    show: false,
  },
  {
    field: 'dbName',
    label: '数据库名称',
    required: true,
    component: 'Input',
  },
  {
    field: 'catalog',
    label: '目录',
    required: true,
    component: 'Input',
  },
  {
    field: 'drive',
    label: '驱动类',
    required: true,
    component: 'Input',
  },
  {
    field: 'dbUrl',
    label: '数据源URL',
    required: true,
    component: 'Input',
  },

  {
    field: 'dbUsername',
    label: '账号',
    required: true,
    component: 'Input',
  },
  {
    field: 'dbPassword',
    label: '密码',
    required: true,
    component: 'Input',
  },
];
